<!documentTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>用户登录</title>
		<script src="../js/mui.min.js"></script>
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">用户登录</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>用户名</label>
				<input type="text" class="mui-input-clear" id="username" placeholder="请输入用户名">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input type="password" class="mui-input-password" id="password" placeholder="请输入密码">
				</div>
				<div class="mui-button-row">
					<button type="button" onclick="login();" class="mui-btn mui-btn-primary" >登录</button>
					<button type="button" onclick="signUp();" class="mui-btn" >注册</button>
				</div>
			</form>
			<div style="height:44px;"></div>
		</div>
		
		<script>
			mui.init();
			
			function login(){
				var username = document.getElementById('username').value;
				var password = document.getElementById('password').value;
				//alert('u:'+username+','+'p:'+password)
				var url = localStorage.getItem('remoteAddress') + '/api/userLogin';
				mui.post(url,{
					userName: username,
					password: password
				},function(data){
					var data = data.data;
					//服务器返回响应，根据响应结果，分析是否登录成功；
					localStorage.setItem('userIn', data.userIn);
					userIn = localStorage.getItem('userIn');
					if(userIn == '1'){
						mui.toast('登陆成功');
						//alert(data.username);
						localStorage.setItem('userName', data.username);
						plus.webview.close('loginPage');
					}else{
						mui.toast('用户名或密码错误');
						document.getElementById('username').value = '';
						document.getElementById('password').value = '';
					}
				},'json'
			);
				
			}
			
			function signUp(){
				plus.webview.close('loginPage');
				var signUpPage = plus.webview.open('signUpPage.html', 'signUpPage', {}, 'slide-in-right', 200);
			}
			
		</script>
	</body>
</html>
